<?php
namespace app\index\controller;

use app\index\model\AccountDiaoModel;
use app\index\model\ArchiveDiaoModel;
use app\index\model\ArchiveJiaoListModel;
use app\index\model\ArchiveJiaoModel;
use app\index\model\ArchiveModel;
use app\index\model\ArchiveOutModel;
use app\index\model\ArchiveTongModel;
use app\index\model\ArchiveZhuanModel;
use app\index\model\CertPerruModel;
use app\index\model\CertPersonModel;
use app\index\model\CertZhaoModel;
use app\index\model\DeptModel;
use app\index\model\FlowBillModel;
use app\index\model\FlowLogModel;
use app\index\model\HuiModel;
use app\index\model\KaoBanModel;
use app\index\model\KaochaiModel;
use app\index\model\KaoChuModel;
use app\index\model\KaoJiaModel;
use app\index\model\TongyongModel;
use app\index\model\UserGangModel;
use app\index\model\UserModel;
use app\index\model\WageListModel;
use app\index\model\WageModel;
use app\index\service\CertService;
use app\index\service\FlowService;
use app\index\service\HumanService;
use app\index\service\MenuService;
use app\index\service\OptService;
use app\index\service\UserService;
use app\index\validate\CertPerson;
use think\Db;
use think\Request;

class Human extends Common
{
    public function list_archive(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['arc.deleted_user','=', 0];
        $where[] = ['arc.comid','=',$this->userinfo['comid']];
        $where[] = ['arc.state','=','在职'];


        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['arc.name|arc.number|arc.idcard|arc.nation|arc.jiguan|arc.mian|arc.tel|arc.socialareas','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['name']) && !empty($param['name'])){
            $where[] = ['arc.name','like', '%'.$param['name'].'%'];
        }
        if(isset($param['number']) && !empty($param['number'])){
            $where[] = ['arc.number','like', '%'.$param['number'].'%'];
        }
        if(isset($param['idcard']) && !empty($param['idcard'])){
            $where[] = ['arc.idcard','like', '%'.$param['idcard'].'%'];
        }
        if(isset($param['sex']) && !empty($param['sex'])){
            $where[] = ['arc.sex','=', $param['sex']];
        }
        if(isset($param['birdt']) && !empty($param['birdt'])){
            $where[] = ['arc.birdt','between', explode(' - ', $param['birdt'])];
        }
        if(isset($param['nation']) && !empty($param['nation'])){
            $where[] = ['arc.nation','like', '%'.$param['nation'].'%'];
        }
        if(isset($param['jiguan']) && !empty($param['jiguan'])){
            $where[] = ['arc.jiguan','like', '%'.$param['jiguan'].'%'];
        }
        if(isset($param['mian']) && !empty($param['mian'])){
            $where[] = ['arc.mian','like', '%'.$param['mian'].'%'];
        }
        if(isset($param['addr']) && !empty($param['addr'])){
            $where[] = ['arc.addr','like', '%'.$param['addr'].'%'];
        }
        if(isset($param['tel']) && !empty($param['tel'])){
            $where[] = ['arc.tel','like', '%'.$param['tel'].'%'];
        }
        if(isset($param['jiner']) && !empty($param['jiner'])){
            $where[] = ['arc.jiner','like', '%'.$param['jiner'].'%'];
        }
        if(isset($param['jintel']) && !empty($param['jintel'])){
            $where[] = ['arc.jintel','like', '%'.$param['jintel'].'%'];
        }
        if(isset($param['school']) && !empty($param['school'])){
            $where[] = ['arc.school','like', '%'.$param['school'].'%'];
        }
        if(isset($param['xueli']) && !empty($param['xueli'])){
            $where[] = ['arc.xueli','=', $param['xueli']];
        }
        if(isset($param['major']) && !empty($param['major'])){
            $where[] = ['arc.major','like', '%'.$param['major'].'%'];
        }
        if(isset($param['schooldt']) && !empty($param['schooldt'])){
            $where[] = ['arc.schooldt','between', explode(' - ', $param['schooldt'])];
        }
        if(isset($param['zhilevel']) && !empty($param['zhilevel'])){
            $where[] = ['arc.zhilevel','like', '%'.$param['zhilevel'].'%'];
        }
        if(isset($param['state']) && !empty($param['state'])){
            $where[] = ['arc.state','=', $param['state']];
        }
        if(isset($param['nature']) && !empty($param['nature'])){
            $where[] = ['arc.nature','=', $param['nature']];
        }
        if(isset($param['intodt']) && !empty($param['intodt'])){
            $where[] = ['arc.intodt','between', explode(' - ', $param['intodt'])];
        }
        if(isset($param['zhuandt']) && !empty($param['zhuandt'])){
            $where[] = ['arc.zhuandt','between', explode(' - ', $param['zhuandt'])];
        }
        if(isset($param['outdt']) && !empty($param['outdt'])){
            $where[] = ['arc.outdt','between', explode(' - ', $param['outdt'])];
        }
        if(isset($param['outtype']) && !empty($param['outtype'])){
            $where[] = ['arc.outtype','=', $param['outtype']];
        }
        if(isset($param['deptid']) && !empty($param['deptid'])){
            $where[] = ['arc.deptid','=', $param['deptid']];
        }
        $whereGangid = '';
        if(isset($param['gangid']) && $param['gangid'] != ''){
            $whereGangid = Db::raw("FIND_IN_SET(".$param['gangid'].",`arc`.`gangid`)");
        }
        if(isset($param['social']) && !empty($param['social'])){
            $where[] = ['arc.social','=', $param['social']];
        }
        if(isset($param['socialareas']) && !empty($param['socialareas'])){
            $where[] = ['arc.socialareas','like', '%'.$param['socialareas'].'%'];
        }
        if(isset($param['socstartdt']) && !empty($param['socstartdt'])){
            $where[] = ['arc.socstartdt','between', explode(' - ', $param['socstartdt'])];
        }
        if(isset($param['socenddt']) && !empty($param['socenddt'])){
            $where[] = ['arc.socenddt','between', explode(' - ', $param['socenddt'])];
        }
        if(isset($param['shenum']) && !empty($param['shenum'])){
            $where[] = ['arc.shenum','like', '%'.$param['shenum'].'%'];
        }
        if(isset($param['gongnum']) && !empty($param['gongnum'])){
            $where[] = ['arc.gongnum','like', '%'.$param['gongnum'].'%'];
        }
        if(isset($param['bankname']) && !empty($param['bankname'])){
            $where[] = ['arc.bankname','like', '%'.$param['bankname'].'%'];
        }
        if(isset($param['banknum']) && !empty($param['banknum'])){
            $where[] = ['arc.banknum','like', '%'.$param['banknum'].'%'];
        }
        if(isset($param['bankkai']) && !empty($param['bankkai'])){
            $where[] = ['arc.bankkai','like', '%'.$param['bankkai'].'%'];
        }

        $data['nature'] = (new OptService())->get_base_info('person_nature');
        $data['is_nature'] = isset($param['nature']) ? $param['nature'] : '';

        $data['social'] = (new OptService())->get_base_info('person_social');
        $data['is_social'] = isset($param['social']) ? $param['social'] : '';

        $data['xueli'] = (new OptService())->get_base_info('person_xueli');
        $data['is_xueli'] = isset($param['xueli']) ? $param['xueli'] : '';

        $data['gangArr'] = (new UserService())->get_usergang_all();
        $data['is_gangid'] = isset($param['gangid']) ? $param['gangid'] : '';

        $data['data'] = CertPersonModel::alias('arc')
            ->field('arc.*')
            ->where($where)
            ->where($whereGangid)
            ->where((new MenuService())->get_miss_where('archive', 'arc'))
            ->order('arc.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['deptid_name'] = DeptModel::get_name_by_pk($item['deptid']);
                $item['gangid_name'] = UserGangModel::get_name_by_ids($item['gangid'],' / ');
                $item['nature'] = (new OptService())->get_base_showname('person_nature', $item['nature']);
                $item['social'] = (new OptService())->get_base_showname('person_social', $item['social']);
                $item['xueli'] = (new OptService())->get_base_showname('person_xueli', $item['xueli']);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('archive');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_archive(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['name'])){
                return outputJson(4000, '请输入人员姓名');
            }
            if((new HumanService())->check_archive_name($param['name'])){
                return outputJson(4000, '人员姓名已存在');
            }
            if(empty($param['nature'])){
                return outputJson(4000, '请选择人员性质');
            }
            if(empty($param['deptid'])){
                return outputJson(4000, '请选择所在部门');
            }
            if(empty($param['social'])){
                return outputJson(4000, '请选择社保状态');
            }

            $param['comid'] = $this->userinfo['comid'];
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['chanid'] = (new UserService())->get_dept_chanid($param['deptid']);


            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);


            Db::startTrans();
            try {
                $id = ArchiveModel::insertGetId($param);
                (new OptService())->relation_file($files,'archive',$id);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'archive', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'archive', $id, '员工档案');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $data['gangArr'] = (new UserService())->get_usergang_all();
            $data['nature'] = (new OptService())->get_base_info('person_nature');
            $data['social'] = (new OptService())->get_base_info('person_social');
            $data['xueli'] = (new OptService())->get_base_info('person_xueli');
            $data['areas'] = (new OptService())->get_city_cader();
            return outputJson(2000,lang('code_2000'), $data);
        }
    }
    public function edit_archive(Request $request){
        if($request->isPost()){
            $param = $request->post();
            $old = ArchiveModel::where(['id'=>$param['id']])->find();

            if(empty($param['name'])){
                return outputJson(4000, '请输入人员姓名');
            }
            if((new HumanService())->check_archive_name($param['name'], $param['id'])){
                return outputJson(4000, '人员姓名已存在');
            }
            if(empty($param['nature'])){
                return outputJson(4000, '请选择人员性质');
            }
            if(empty($param['deptid'])){
                return outputJson(4000, '请选择所在部门');
            }
            if(empty($param['social'])){
                return outputJson(4000, '请选择社保状态');
            }


            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');

            $param['chanid'] = (new UserService())->get_dept_chanid($param['deptid']);

            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);



            Db::startTrans();
            try {
                ArchiveModel::update($param);
                (new OptService())->relation_file($files,'archive',$param['id']);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'archive', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'archive', $param['id'], '员工档案');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = ArchiveModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }
            $data['data']['gangid'] = explode(',', $data['data']['gangid']);
            $data['data']['deptid_info'] = (new UserService())->get_users_part_arr($data['data']['deptid'], 'dept');

            $data['gangArr'] = (new UserService())->get_usergang_all();
            $data['nature'] = (new OptService())->get_base_info('person_nature');
            $data['social'] = (new OptService())->get_base_info('person_social');
            $data['xueli'] = (new OptService())->get_base_info('person_xueli');
            $data['areas'] = (new OptService())->get_city_cader();
            $data['files'] = (new OptService())->get_file('archive', $data['data']['id']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_archive(Request $request){
        $param = $request->post();
        $data = ArchiveModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            ArchiveModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'archive', $data['id'], '员工档案');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_archive(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = ArchiveModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }

        $data['data']['deptid_name'] = DeptModel::get_name_by_pk($data['data']['deptid']);
        $data['data']['gangid_name'] = UserGangModel::get_name_by_ids($data['data']['gangid'],' / ');
        $data['data']['nature'] = (new OptService())->get_base_showname('person_nature', $data['data']['nature']);
        $data['data']['social'] = (new OptService())->get_base_showname('person_social', $data['data']['social']);
        $data['data']['xueli'] = (new OptService())->get_base_showname('person_xueli', $data['data']['xueli']);

        $data['files'] = (new OptService())->get_file('archive', $data['data']['id']);
        return outputJson(2000,lang('code_2000'), $data);
    }



    public function list_archive_tong(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['tong.deleted_user','=', 0];
        $where[] = ['tong.comid','=',$this->userinfo['comid']];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['arc.name|tong.number','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['name']) && !empty($param['name'])){
            $where[] = ['arc.name','like', '%'.$param['name'].'%'];
        }
        if(isset($param['number']) && !empty($param['number'])){
            $where[] = ['tong.number','like', '%'.$param['number'].'%'];
        }
        if(isset($param['tongtype']) && !empty($param['tongtype'])){
            $where[] = ['tong.tongtype','=', $param['tongtype']];
        }
        if(isset($param['xiandt']) && !empty($param['xiandt'])){
            $where[] = ['tong.xiandt','between', explode(' - ', $param['xiandt'])];
        }
        if(isset($param['xianzhidt']) && !empty($param['xianzhidt'])){
            $where[] = ['tong.xianzhidt','between', explode(' - ', $param['xianzhidt'])];
        }
        if(isset($param['shidt']) && !empty($param['shidt'])){
            $where[] = ['tong.shidt','between', explode(' - ', $param['shidt'])];
        }
        if(isset($param['shizhidt']) && !empty($param['shizhidt'])){
            $where[] = ['tong.shizhidt','between', explode(' - ', $param['shizhidt'])];
        }
        if(isset($param['gongfee']) && !empty($param['gongfee'])){
            $where[] = ['tong.gongfee','like', '%'.$param['gongfee'].'%'];
        }
        if(isset($param['zhuanfee']) && !empty($param['zhuanfee'])){
            $where[] = ['tong.zhuanfee','like', '%'.$param['zhuanfee'].'%'];
        }
        if(isset($param['state']) && !empty($param['state'])){
            $where[] = ['tong.state','=', $param['state']];
        }
        if(isset($param['nature']) && !empty($param['nature'])){
            $where[] = ['tong.nature','=', $param['nature']];
        }
        if(isset($param['zhongdt']) && !empty($param['zhongdt'])){
            $where[] = ['tong.zhongdt','between', explode(' - ', $param['zhongdt'])];
        }
        if(isset($param['qiandt']) && !empty($param['qiandt'])){
            $where[] = ['tong.qiandt','between', explode(' - ', $param['qiandt'])];
        }

        $data['state'] = (new HumanService())->get_arc_tong_state();
        $data['is_state'] = isset($param['state']) ? $param['state'] : '';

        $data['nature'] = (new HumanService())->get_arc_tong_nature();
        $data['is_nature'] = isset($param['nature']) ? $param['nature'] : '';

        $data['tongtype'] = (new OptService())->get_base_info('qi_archive_tongtype');
        $data['is_tongtype'] = isset($param['tongtype']) ? $param['tongtype'] : '';


        $data['data'] = ArchiveTongModel::alias('tong')
            ->field('tong.*,arc.name')
            ->join('cert_person arc','arc.id=tong.arcid')
            ->where($where)
            ->where((new MenuService())->get_miss_where('archive_tong', 'tong'))
            ->order('tong.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['tongtype'] = (new OptService())->get_base_showname('qi_archive_tongtype', $item['tongtype']);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('archive_tong');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_archive_tong(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['arcid'])){
                return outputJson(4000, '请选择人员');
            }
            if(empty($param['xiandt'])){
                return outputJson(4000, '请选择期限起');
            }
            if(empty($param['state'])){
                return outputJson(4000, '请选择合同状态');
            }
            if(empty($param['nature'])){
                return outputJson(4000, '请选择合同性质');
            }

            $param['comid'] = $this->userinfo['comid'];
            $param['status'] = 1;
            $param['isturn'] = 1;
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];
            $param['chanid'] = (new UserService())->get_user_chanid();


            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);


            Db::startTrans();
            try {
                $id = ArchiveTongModel::insertGetId($param);
                (new OptService())->relation_file($files,'archive_tong',$id);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'archive_tong', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'archive_tong', $id, '劳动合同');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $data['tongtype'] = (new OptService())->get_base_info('qi_archive_tongtype');
            $data['state'] = (new HumanService())->get_arc_tong_state();
            $data['nature'] = (new HumanService())->get_arc_tong_nature();
            return outputJson(2000,lang('code_2000'), $data);
        }
    }
    public function edit_archive_tong(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['xiandt'])){
                return outputJson(4000, '请选择期限起');
            }
            if(empty($param['state'])){
                return outputJson(4000, '请选择合同状态');
            }
            if(empty($param['nature'])){
                return outputJson(4000, '请选择合同性质');
            }


            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');

            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);



            Db::startTrans();
            try {
                ArchiveTongModel::update($param);
                (new OptService())->relation_file($files,'archive_tong',$param['id']);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'archive_tong', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'archive_tong', $param['id'], '劳动合同');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = ArchiveTongModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }

            $data['data']['arcid_name'] = CertPersonModel::where(['id'=>$data['data']['arcid']])->value('name');

            $data['tongtype'] = (new OptService())->get_base_info('qi_archive_tongtype');
            $data['state'] = (new HumanService())->get_arc_tong_state();
            $data['nature'] = (new HumanService())->get_arc_tong_nature();
            $data['files'] = (new OptService())->get_file('archive_tong', $data['data']['id']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_archive_tong(Request $request){
        $param = $request->post();
        $data = ArchiveTongModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            ArchiveTongModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'archive_tong', $data['id'], '劳动合同');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_archive_tong(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = ArchiveTongModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }

        $arcinfo = CertPersonModel::where(['id'=>$data['data']['arcid']])->find();
        $data['arcinfo'] = $arcinfo;

        $data['data']['tongtype'] = (new OptService())->get_base_showname('qi_archive_tongtype', $data['data']['tongtype']);
        $data['files'] = (new OptService())->get_file('archive_tong', $data['data']['id']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }




    public function list_wage(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['wage.deleted_user','=', 0];
        $where[] = ['wage.comid','=',$this->userinfo['comid']];
        $where[] = ['wage.isturn','=',1];
        $where[] = ['wage.status','in',[0,1]];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['wage.number|wage.title','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['month']) && !empty($param['month'])){
            $where[] = ['wage.month','between', explode(' - ', $param['month'])];
        }
        if(isset($param['number']) && !empty($param['number'])){
            $where[] = ['wage.number','like', '%'.$param['number'].'%'];
        }
        if(isset($param['title']) && !empty($param['title'])){
            $where[] = ['wage.title','like', '%'.$param['title'].'%'];
        }
        if(isset($param['yingfee']) && !empty($param['yingfee'])){
            $where[] = ['wage.yingfee','=', $param['yingfee']];
        }
        if(isset($param['koufee']) && !empty($param['koufee'])){
            $where[] = ['wage.koufee','=', $param['koufee']];
        }
        if(isset($param['money']) && !empty($param['money'])){
            $where[] = ['wage.money','=', $param['money']];
        }
        if(isset($param['dt']) && !empty($param['dt'])){
            $where[] = ['wage.dt','between', explode(' - ', $param['dt'])];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['wage.status','=', $param['status']];
        }

        $data['data'] = WageModel::alias('wage')
            ->field('wage.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('wage', 'wage'))
            ->order('wage.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){

                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('wage');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_wage(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['month'])){
                return outputJson(4000, '请选择工资月份');
            }
            if(empty($param['title'])){
                return outputJson(4000, '请输入工资标题');
            }
            if(empty($param['dt'])){
                return outputJson(4000, '请选择计划发放日期');
            }


            $param['number'] = (new HumanService())->create_wage_number($param['month']);
            $param['comid'] = $this->userinfo['comid'];
            $param['status'] = 1;
            $param['isturn'] = 1;
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];
            $param['chanid'] = (new UserService())->get_user_chanid();


            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);

            $list = array_filter($param['list']);
            unset($param['list']);
            if(count($list) < 1){
                return outputJson(4000, '请输入工资明细');
            }

            Db::startTrans();
            try {
                $id = WageModel::insertGetId($param);

                foreach($list as $vv){
                    $vv['wageid'] = $id;
                    WageListModel::insert($vv);
                }

                (new OptService())->relation_file($files,'wage',$id);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'wage', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'wage', $id, '工资表');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            return outputJson(2000,lang('code_2000'), []);
        }
    }
    public function edit_wage(Request $request){
        if($request->isPost()){
            $param = $request->post();
            $old = WageModel::where(['id'=>$param['id']])->find();

            if(empty($param['month'])){
                return outputJson(4000, '请选择工资月份');
            }
            if(empty($param['title'])){
                return outputJson(4000, '请输入工资标题');
            }
            if(empty($param['dt'])){
                return outputJson(4000, '请选择计划发放日期');
            }

            if($old['month'] != $param['month']){
                $param['number'] = (new HumanService())->create_wage_number($param['month']);
            }

            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');

            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);

            $list = array_filter($param['list']);
            unset($param['list']);
            if(count($list) < 1){
                return outputJson(4000, '请输入工资明细');
            }

            Db::startTrans();
            try {
                WageModel::update($param);

                WageListModel::where(['wageid'=>$param['id']])->delete();
                foreach($list as $vv){
                    $vv['wageid'] = $param['id'];
                    WageListModel::insert($vv);
                }

                (new OptService())->relation_file($files,'wage',$param['id']);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'wage', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'wage', $param['id'], '工资表');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = WageModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }

            $list = WageListModel::where(['wageid'=>$data['data']['id']])->select()->toArray();
            $data['list'] = $list;

            $data['files'] = (new OptService())->get_file('wage', $data['data']['id']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_wage(Request $request){
        $param = $request->post();
        $data = WageModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            WageModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'wage', $data['id'], '工资表');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_wage(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = WageModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }

        $list = WageListModel::where(['wageid'=>$data['data']['id']])->select()->toArray();
        $data['list'] = $list;

        $data['files'] = (new OptService())->get_file('wage', $data['data']['id']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }



    public function list_archive_diao(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['diao.deleted_user','=', 0];
        $where[] = ['diao.comid','=',$this->userinfo['comid']];
        $where[] = ['diao.isturn','=',1];
        $where[] = ['diao.status','in',[0,1]];


        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['diao.flowuser|diao.flowdept','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['flowuser']) && !empty($param['flowuser'])){
            $where[] = ['diao.flowuser','like', '%'.$param['flowuser'].'%'];
        }
        if(isset($param['flowdept']) && !empty($param['flowdept'])){
            $where[] = ['diao.flowdept','like', '%'.$param['flowdept'].'%'];
        }
        if(isset($param['diaotype']) && !empty($param['diaotype'])){
            $where[] = ['diao.diaotype','=', $param['diaotype']];
        }
        if(isset($param['deptname']) && !empty($param['deptname'])){
            $where[] = ['diao.deptname','like', '%'.$param['deptname'].'%'];
        }
        if(isset($param['gangname']) && !empty($param['gangname'])){
            $where[] = ['diao.gangname','like', '%'.$param['gangname'].'%'];
        }
        if(isset($param['diaodept']) && !empty($param['diaodept'])){
            $where[] = ['diao.diaodept','=', $param['diaodept']];
        }
        $whereDiaogang = '';
        if(isset($param['diaogang']) && $param['diaogang'] != ''){
            $whereDiaogang = Db::raw("FIND_IN_SET(".$param['diaogang'].",`diao`.`diaogang`)");
        }
        if(isset($param['dt']) && !empty($param['dt'])){
            $where[] = ['diao.dt','between', explode(' - ', $param['dt'])];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['diao.status','=', $param['status']];
        }


        $data['diaotype'] = (new OptService())->get_base_info('qi_archive_diaotype');
        $data['is_diaotype'] = isset($param['diaotype']) ? $param['diaotype'] : '';


        $data['deptArr'] = (new UserService())->get_deptinfo_all();
        $data['is_diaodept'] = isset($param['diaodept']) ? $param['diaodept'] : '';

        $data['gangArr'] = (new UserService())->get_usergang_all();
        $data['is_diaogang'] = isset($param['diaogang']) ? $param['diaogang'] : '';

        $data['data'] = ArchiveDiaoModel::alias('diao')
            ->field('diao.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('archive_diao', 'diao'))
            ->order('diao.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['diaotype'] = (new OptService())->get_base_showname('qi_archive_diaotype', $item['diaotype']);
                $item['diaodept_name'] = DeptModel::get_name_by_pk($item['diaodept']);
                $item['diaogang_name'] = UserGangModel::get_name_by_ids($item['diaogang'],' / ');
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('archive_diao');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_archive_diao(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['arcid'])){
                return outputJson(4000, '请选择人员');
            }
            if(empty($param['diaotype'])){
                return outputJson(4000, '请选择调动类型');
            }
            if(empty($param['diaodept'])){
                return outputJson(4000, '请选择调至部门');
            }
            if(empty($param['diaogang'])){
                return outputJson(4000, '请选择调至岗位');
            }
            if(empty($param['dt'])){
                return outputJson(4000, '请选择调动日期');
            }

            $param['comid'] = $this->userinfo['comid'];
            $param['status'] = 1;
            $param['isturn'] = 1;
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];
            $param['chanid'] = (new UserService())->get_user_chanid();


            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);


            Db::startTrans();
            try {
                $id = ArchiveDiaoModel::insertGetId($param);
                ArchiveModel::where(['id'=>$param['arcid']])->update([
                    'deptid' => $param['diaodept'],
                    'gangid' => $param['diaogang'],
                ]);

                (new OptService())->relation_file($files,'archive_diao',$id);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'archive_diao', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'archive_diao', $id, '调动');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $data['gangArr'] = (new UserService())->get_usergang_all();
            $data['diaotype'] = (new OptService())->get_base_info('qi_archive_diaotype');
            return outputJson(2000,lang('code_2000'), $data);
        }
    }
    public function edit_archive_diao(Request $request){
        if($request->isPost()){
            $param = $request->post();
            $old = ArchiveDiaoModel::where(['id'=>$param['id']])->find();

            if(empty($param['diaotype'])){
                return outputJson(4000, '请选择调动类型');
            }
            if(empty($param['diaodept'])){
                return outputJson(4000, '请选择调至部门');
            }
            if(empty($param['diaogang'])){
                return outputJson(4000, '请选择调至岗位');
            }
            if(empty($param['dt'])){
                return outputJson(4000, '请选择调动日期');
            }


            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');

            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);



            Db::startTrans();
            try {
                ArchiveDiaoModel::update($param);
                ArchiveModel::where(['id'=>$old['arcid']])->update([
                    'deptid' => $param['diaodept'],
                    'gangid' => $param['diaogang'],
                ]);
                (new OptService())->relation_file($files,'archive_diao',$param['id']);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'archive_diao', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'archive_diao', $param['id'], '调动');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = ArchiveDiaoModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }
            $data['data']['diaogang'] = explode(',', $data['data']['diaogang']);
            $data['data']['arcid_name'] = ArchiveModel::where(['id'=>$data['data']['arcid']])->value('name');
            $data['data']['diaodept_info'] = (new UserService())->get_users_part_arr($data['data']['diaodept'], 'dept');

            $data['gangArr'] = (new UserService())->get_usergang_all();
            $data['diaotype'] = (new OptService())->get_base_info('qi_archive_diaotype');
            $data['files'] = (new OptService())->get_file('archive_diao', $data['data']['id']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_archive_diao(Request $request){
        $param = $request->post();
        $data = ArchiveDiaoModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            ArchiveDiaoModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'archive_diao', $data['id'], '调动');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_archive_diao(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = ArchiveDiaoModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }

        $data['data']['diaodept_name'] = DeptModel::get_name_by_pk($data['data']['diaodept']);
        $data['data']['diaogang_name'] = UserGangModel::get_name_by_ids($data['data']['diaogang'],' / ');


        $data['data']['diaotype'] = (new OptService())->get_base_showname('qi_archive_diaotype', $data['data']['diaotype']);
        $data['files'] = (new OptService())->get_file('archive_diao', $data['data']['id']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }


    public function list_archive_zhuan(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['zhuan.deleted_user','=', 0];
        $where[] = ['zhuan.comid','=',$this->userinfo['comid']];
        $where[] = ['zhuan.isturn','=',1];
        $where[] = ['zhuan.status','in',[0,1]];


        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['zhuan.flowuser|zhuan.flowdept','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['flowuser']) && !empty($param['flowuser'])){
            $where[] = ['zhuan.flowuser','like', '%'.$param['flowuser'].'%'];
        }
        if(isset($param['flowdept']) && !empty($param['flowdept'])){
            $where[] = ['zhuan.flowdept','like', '%'.$param['flowdept'].'%'];
        }
        if(isset($param['intodt']) && !empty($param['intodt'])){
            $where[] = ['zhuan.intodt','between', explode(' - ', $param['intodt'])];
        }
        if(isset($param['shidaodt']) && !empty($param['shidaodt'])){
            $where[] = ['zhuan.shidaodt','between', explode(' - ', $param['shidaodt'])];
        }
        if(isset($param['gongfee']) && !empty($param['gongfee'])){
            $where[] = ['zhuan.gongfee','like', '%'.$param['gongfee'].'%'];
        }
        if(isset($param['zhuandt']) && !empty($param['zhuandt'])){
            $where[] = ['zhuan.zhuandt','between', explode(' - ', $param['zhuandt'])];
        }
        if(isset($param['zhuanfee']) && !empty($param['zhuanfee'])){
            $where[] = ['zhuan.zhuanfee','like', '%'.$param['zhuanfee'].'%'];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['zhuan.status','=', $param['status']];
        }

        $data['data'] = ArchiveZhuanModel::alias('zhuan')
            ->field('zhuan.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('archive_zhuan', 'zhuan'))
            ->order('zhuan.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('archive_zhuan');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_archive_zhuan(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['arcid'])){
                return outputJson(4000, '请选择人员');
            }
            if(empty($param['intodt'])){
                return outputJson(4000, '请选择入职日期');
            }
            if(empty($param['shidaodt'])){
                return outputJson(4000, '请选择试用期到期日期');
            }
            if($param['gongfee'] == ''){
                return outputJson(4000, '请输入试用期工资');
            }
            if(empty($param['zhuandt'])){
                return outputJson(4000, '请选择申请转正日期');
            }
            if($param['zhuanfee'] == ''){
                return outputJson(4000, '请输入转正工资');
            }

            $param['comid'] = $this->userinfo['comid'];
            $param['status'] = 1;
            $param['isturn'] = 1;
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];
            $param['chanid'] = (new UserService())->get_user_chanid();


            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);


            Db::startTrans();
            try {
                $id = ArchiveZhuanModel::insertGetId($param);

                (new OptService())->relation_file($files,'archive_zhuan',$id);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'archive_zhuan', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'archive_zhuan', $id, '转正');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            return outputJson(2000,lang('code_2000'), []);
        }
    }
    public function edit_archive_zhuan(Request $request){
        if($request->isPost()){
            $param = $request->post();
            $old = ArchiveZhuanModel::where(['id'=>$param['id']])->find();

            if(empty($param['intodt'])){
                return outputJson(4000, '请选择入职日期');
            }
            if(empty($param['shidaodt'])){
                return outputJson(4000, '请选择试用期到期日期');
            }
            if($param['gongfee'] == ''){
                return outputJson(4000, '请输入试用期工资');
            }
            if(empty($param['zhuandt'])){
                return outputJson(4000, '请选择申请转正日期');
            }
            if($param['zhuanfee'] == ''){
                return outputJson(4000, '请输入转正工资');
            }

            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');

            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);



            Db::startTrans();
            try {
                ArchiveZhuanModel::update($param);

                (new OptService())->relation_file($files,'archive_zhuan',$param['id']);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'archive_zhuan', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'archive_zhuan', $param['id'], '转正');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = ArchiveZhuanModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }

            $arcinfo = ArchiveModel::where(['id'=>$data['data']['arcid']])->find();
            $arcinfo['deptname'] = DeptModel::get_name_by_pk($arcinfo['deptid']);
            $arcinfo['gangname'] = UserGangModel::get_name_by_ids($arcinfo['gangid'],' / ');
            $data['arcinfo'] = $arcinfo;

            $data['files'] = (new OptService())->get_file('archive_zhuan', $data['data']['id']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_archive_zhuan(Request $request){
        $param = $request->post();
        $data = ArchiveZhuanModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            ArchiveZhuanModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'archive_zhuan', $data['id'], '转正');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_archive_zhuan(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = ArchiveZhuanModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }



        $data['files'] = (new OptService())->get_file('archive_zhuan', $data['data']['id']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }



    public function list_archive_out(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['out.deleted_user','=', 0];
        $where[] = ['out.comid','=',$this->userinfo['comid']];
        $where[] = ['out.isturn','=',1];
        $where[] = ['out.status','in',[0,1]];


        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['out.flowuser|out.flowdept','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['flowuser']) && !empty($param['flowuser'])){
            $where[] = ['out.flowuser','like', '%'.$param['flowuser'].'%'];
        }
        if(isset($param['flowdept']) && !empty($param['flowdept'])){
            $where[] = ['out.flowdept','like', '%'.$param['flowdept'].'%'];
        }
        if(isset($param['intodt']) && !empty($param['intodt'])){
            $where[] = ['out.intodt','between', explode(' - ', $param['intodt'])];
        }
        if(isset($param['outdt']) && !empty($param['outdt'])){
            $where[] = ['out.outdt','between', explode(' - ', $param['outdt'])];
        }
        if(isset($param['outtype']) && !empty($param['outtype'])){
            $where[] = ['out.outtype','like', $param['outtype']];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['out.status','=', $param['status']];
        }

        $data['data'] = ArchiveOutModel::alias('out')
            ->field('out.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('archive_out', 'out'))
            ->order('out.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('archive_out');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_archive_out(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['arcid'])){
                return outputJson(4000, '请选择人员');
            }
            if(empty($param['intodt'])){
                return outputJson(4000, '请选择入职日期');
            }
            if(empty($param['outdt'])){
                return outputJson(4000, '请选择申请离职日期');
            }
            if(empty($param['outtype'])){
                return outputJson(4000, '请选择离职类型');
            }


            $param['comid'] = $this->userinfo['comid'];
            $param['status'] = 1;
            $param['isturn'] = 1;
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];
            $param['chanid'] = (new UserService())->get_user_chanid();


            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);


            Db::startTrans();
            try {
                $id = ArchiveOutModel::insertGetId($param);


                (new OptService())->relation_file($files,'archive_out',$id);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'archive_out', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'archive_out', $id, '离职');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $data = [];
            return outputJson(2000,lang('code_2000'), $data);
        }
    }
    public function edit_archive_out(Request $request){
        if($request->isPost()){
            $param = $request->post();
            $old = ArchiveOutModel::where(['id'=>$param['id']])->find();

            if(empty($param['intodt'])){
                return outputJson(4000, '请选择入职日期');
            }
            if(empty($param['outdt'])){
                return outputJson(4000, '请选择申请离职日期');
            }
            if(empty($param['outtype'])){
                return outputJson(4000, '请选择离职类型');
            }

            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');

            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);



            Db::startTrans();
            try {
                ArchiveOutModel::update($param);

                (new OptService())->relation_file($files,'archive_out',$param['id']);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'archive_out', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'archive_out', $param['id'], '离职');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = ArchiveOutModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }

            $arcinfo = ArchiveModel::where(['id'=>$data['data']['arcid']])->find();
            $arcinfo['deptname'] = DeptModel::get_name_by_pk($arcinfo['deptid']);
            $arcinfo['gangname'] = UserGangModel::get_name_by_ids($arcinfo['gangid'],' / ');
            $data['arcinfo'] = $arcinfo;

            $data['files'] = (new OptService())->get_file('archive_out', $data['data']['id']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_archive_out(Request $request){
        $param = $request->post();
        $data = ArchiveOutModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            ArchiveOutModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'archive_out', $data['id'], '离职');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_archive_out(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = ArchiveOutModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }

        $data['files'] = (new OptService())->get_file('archive_out', $data['data']['id']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }





    public function list_kao_jia(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['jia.deleted_user','=', 0];
        $where[] = ['jia.comid','=',$this->userinfo['comid']];
        $where[] = ['jia.isturn','=',1];
        $where[] = ['jia.status','in',[0,1]];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['jia.flowuser|jia.flowdept','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['flowuser']) && !empty($param['flowuser'])){
            $where[] = ['jia.flowuser','like', '%'.$param['flowuser'].'%'];
        }
        if(isset($param['flowdept']) && !empty($param['flowdept'])){
            $where[] = ['jia.flowdept','like', '%'.$param['flowdept'].'%'];
        }
        if(isset($param['jiatype']) && !empty($param['jiatype'])){
            $where[] = ['jia.jiatype','=', $param['jiatype']];
        }
        if(isset($param['startdt']) && !empty($param['startdt'])){
            $where[] = ['jia.startdt','between', explode(' - ', $param['startdt'])];
        }
        if(isset($param['enddt']) && !empty($param['enddt'])){
            $where[] = ['jia.enddt','between', explode(' - ', $param['enddt'])];
        }
        if(isset($param['duration']) && !empty($param['duration'])){
            $where[] = ['jia.duration','like', '%'.$param['duration'].'%'];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['jia.status','=', $param['status']];
        }

        $data['jiatype'] = (new OptService())->get_base_info('qi_kao_jiatype');
        $data['is_jiatype'] = isset($param['jiatype']) ? $param['jiatype'] : '';


        $data['data'] = KaoJiaModel::alias('jia')
            ->field('jia.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('kao_jia', 'jia'))
            ->order('jia.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['jiatype'] = (new OptService())->get_base_showname('qi_kao_jiatype', $item['jiatype']);
                $item['startdt'] = date('Y-m-d H:i', strtotime($item['startdt']));
                $item['enddt'] = date('Y-m-d H:i', strtotime($item['enddt']));
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('kao_jia');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_kao_jia(Request $request){
        if($request->isPost()){
            $param = $request->post();


            if(empty($param['startdt'])){
                return outputJson(4000, '请选择开始时间');
            }
            if(empty($param['enddt'])){
                return outputJson(4000, '请选择结束时间');
            }
            if(empty($param['duration'])){
                return outputJson(4000, '请输入时长');
            }

            $param['comid'] = $this->userinfo['comid'];
            $param['status'] = 1;
            $param['isturn'] = 1;
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];
            $param['chanid'] = (new UserService())->get_user_chanid();


            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);


            Db::startTrans();
            try {
                $id = KaoJiaModel::insertGetId($param);
                (new OptService())->relation_file($files,'kao_jia',$id);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'kao_jia', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'kao_jia', $id, '请假');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $data['jiatype'] = (new OptService())->get_base_info('qi_kao_jiatype');
            return outputJson(2000,lang('code_2000'), $data);
        }
    }
    public function edit_kao_jia(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['userid'])){
                return outputJson(4000, '请选择请假人');
            }
            if(empty($param['startdt'])){
                return outputJson(4000, '请选择开始时间');
            }
            if(empty($param['enddt'])){
                return outputJson(4000, '请选择结束时间');
            }
            if(empty($param['duration'])){
                return outputJson(4000, '请输入时长');
            }


            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');

            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);



            Db::startTrans();
            try {
                KaoJiaModel::update($param);
                (new OptService())->relation_file($files,'kao_jia',$param['id']);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'kao_jia', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'kao_jia', $param['id'], '请假');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = KaoJiaModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }

            $data['data']['userid_info'] = (new UserService())->get_users_part_arr($data['data']['userid'], 'user');

            $data['jiatype'] = (new OptService())->get_base_info('qi_kao_jiatype');
            $data['files'] = (new OptService())->get_file('kao_jia', $data['data']['id']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_kao_jia(Request $request){
        $param = $request->post();
        $data = KaoJiaModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            KaoJiaModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'kao_jia', $data['id'], '请假');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_kao_jia(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = KaoJiaModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }
        $data['data']['startdt'] = date('Y-m-d H:i', strtotime($data['data']['startdt']));
        $data['data']['enddt'] = date('Y-m-d H:i', strtotime($data['data']['enddt']));

        $data['data']['jiatype'] = (new OptService())->get_base_showname('qi_kao_jiatype', $data['data']['jiatype']);
        $data['files'] = (new OptService())->get_file('kao_jia', $data['data']['id']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }

    public function list_kao_chu(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['chu.deleted_user','=', 0];
        $where[] = ['chu.comid','=',$this->userinfo['comid']];
        $where[] = ['chu.isturn','=',1];
        $where[] = ['chu.status','in',[0,1]];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['chu.flowuser|chu.flowdept|chu.dest','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['flowuser']) && !empty($param['flowuser'])){
            $where[] = ['chu.flowuser','like', '%'.$param['flowuser'].'%'];
        }
        if(isset($param['flowdept']) && !empty($param['flowdept'])){
            $where[] = ['chu.flowdept','like', '%'.$param['flowdept'].'%'];
        }
        if(isset($param['dest']) && !empty($param['dest'])){
            $where[] = ['chu.dest','like', '%'.$param['dest'].'%'];
        }
        if(isset($param['startdt']) && !empty($param['startdt'])){
            $where[] = ['chu.startdt','between', explode(' - ', $param['startdt'])];
        }
        if(isset($param['enddt']) && !empty($param['enddt'])){
            $where[] = ['chu.enddt','between', explode(' - ', $param['enddt'])];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['chu.status','=', $param['status']];
        }



        $data['data'] = KaoChuModel::alias('chu')
            ->field('chu.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('kao_chu', 'chu'))
            ->order('chu.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['startdt'] = date('Y-m-d H:i', strtotime($item['startdt']));
                $item['enddt'] = date('Y-m-d H:i', strtotime($item['enddt']));
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('kao_chu');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_kao_chu(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['userid'])){
                return outputJson(4000, '请选择外出人员');
            }
            if(empty($param['dest'])){
                return outputJson(4000, '请输入目的地');
            }
            if(empty($param['startdt'])){
                return outputJson(4000, '请选择开始时间');
            }
            if(empty($param['enddt'])){
                return outputJson(4000, '请选择结束时间');
            }


            $param['comid'] = $this->userinfo['comid'];
            $param['status'] = 1;
            $param['isturn'] = 1;
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];
            $param['chanid'] = (new UserService())->get_user_chanid();


            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);


            Db::startTrans();
            try {
                $id = KaoChuModel::insertGetId($param);
                (new OptService())->relation_file($files,'kao_chu',$id);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'kao_chu', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'kao_chu', $id, '外出');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            return outputJson(2000,lang('code_2000'), []);
        }
    }
    public function edit_kao_chu(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['userid'])){
                return outputJson(4000, '请选择外出人员');
            }
            if(empty($param['dest'])){
                return outputJson(4000, '请输入目的地');
            }
            if(empty($param['startdt'])){
                return outputJson(4000, '请选择开始时间');
            }
            if(empty($param['enddt'])){
                return outputJson(4000, '请选择结束时间');
            }


            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');

            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);



            Db::startTrans();
            try {
                KaoChuModel::update($param);
                (new OptService())->relation_file($files,'kao_chu',$param['id']);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'kao_chu', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'kao_chu', $param['id'], '外出');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = KaoChuModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }

            $data['data']['userid_info'] = (new UserService())->get_users_part_arr($data['data']['userid'], 'user');

            $data['files'] = (new OptService())->get_file('kao_chu', $data['data']['id']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_kao_chu(Request $request){
        $param = $request->post();
        $data = KaoChuModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            KaoChuModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'kao_chu', $data['id'], '外出');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_kao_chu(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = KaoChuModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }

        $data['data']['startdt'] = date('Y-m-d H:i', strtotime($data['data']['startdt']));
        $data['data']['enddt'] = date('Y-m-d H:i', strtotime($data['data']['enddt']));
        $data['files'] = (new OptService())->get_file('kao_chu', $data['data']['id']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }

    public function list_kao_ban(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['ban.deleted_user','=', 0];
        $where[] = ['ban.comid','=',$this->userinfo['comid']];
        $where[] = ['ban.isturn','=',1];
        $where[] = ['ban.status','in',[0,1]];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['ban.flowuser|ban.flowdept|ban.duration','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['flowuser']) && !empty($param['flowuser'])){
            $where[] = ['ban.flowuser','like', '%'.$param['flowuser'].'%'];
        }
        if(isset($param['flowdept']) && !empty($param['flowdept'])){
            $where[] = ['ban.flowdept','like', '%'.$param['flowdept'].'%'];
        }
        if(isset($param['startdt']) && !empty($param['startdt'])){
            $where[] = ['ban.startdt','between', explode(' - ', $param['startdt'])];
        }
        if(isset($param['enddt']) && !empty($param['enddt'])){
            $where[] = ['ban.enddt','between', explode(' - ', $param['enddt'])];
        }
        if(isset($param['duration']) && !empty($param['duration'])){
            $where[] = ['ban.duration','like', '%'.$param['duration'].'%'];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['ban.status','=', $param['status']];
        }


        $data['data'] = KaoBanModel::alias('ban')
            ->field('ban.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('kao_ban', 'ban'))
            ->order('ban.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['startdt'] = date('Y-m-d H:i', strtotime($item['startdt']));
                $item['enddt'] = date('Y-m-d H:i', strtotime($item['enddt']));
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('kao_ban');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_kao_ban(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['userid'])){
                return outputJson(4000, '请选择加班人员');
            }
            if(empty($param['startdt'])){
                return outputJson(4000, '请选择开始时间');
            }
            if(empty($param['enddt'])){
                return outputJson(4000, '请选择结束时间');
            }
            if(empty($param['duration'])){
                return outputJson(4000, '请输入时长');
            }

            $param['comid'] = $this->userinfo['comid'];
            $param['status'] = 1;
            $param['isturn'] = 1;
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];
            $param['chanid'] = (new UserService())->get_user_chanid();


            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);


            Db::startTrans();
            try {
                $id = KaoBanModel::insertGetId($param);
                (new OptService())->relation_file($files,'kao_ban',$id);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'kao_ban', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'kao_ban', $id, '加班');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            return outputJson(2000,lang('code_2000'), []);
        }
    }
    public function edit_kao_ban(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['userid'])){
                return outputJson(4000, '请选择加班人员');
            }
            if(empty($param['startdt'])){
                return outputJson(4000, '请选择开始时间');
            }
            if(empty($param['enddt'])){
                return outputJson(4000, '请选择结束时间');
            }
            if(empty($param['duration'])){
                return outputJson(4000, '请输入时长');
            }


            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');

            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);



            Db::startTrans();
            try {
                KaoBanModel::update($param);
                (new OptService())->relation_file($files,'kao_ban',$param['id']);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'kao_ban', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'kao_ban', $param['id'], '加班');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = KaoBanModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }

            $data['data']['userid_info'] = (new UserService())->get_users_part_arr($data['data']['userid'], 'user');

            $data['files'] = (new OptService())->get_file('kao_ban', $data['data']['id']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_kao_ban(Request $request){
        $param = $request->post();
        $data = KaoBanModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            KaoBanModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'kao_ban', $data['id'], '加班');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_kao_ban(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = KaoBanModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }

        $data['data']['startdt'] = date('Y-m-d H:i', strtotime($data['data']['startdt']));
        $data['data']['enddt'] = date('Y-m-d H:i', strtotime($data['data']['enddt']));
        $data['files'] = (new OptService())->get_file('kao_ban', $data['data']['id']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }

    public function list_kao_chai(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['chai.deleted_user','=', 0];
        $where[] = ['chai.comid','=',$this->userinfo['comid']];
        $where[] = ['chai.isturn','=',1];
        $where[] = ['chai.status','in',[0,1]];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['chai.flowuser|chai.flowdept|chai.chudi|chai.dest|chai.duration','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['flowuser']) && !empty($param['flowuser'])){
            $where[] = ['chai.flowuser','like', '%'.$param['flowuser'].'%'];
        }
        if(isset($param['flowdept']) && !empty($param['flowdept'])){
            $where[] = ['chai.flowdept','like', '%'.$param['flowdept'].'%'];
        }
        if(isset($param['chudi']) && !empty($param['chudi'])){
            $where[] = ['chai.chudi','like', '%'.$param['chudi'].'%'];
        }
        if(isset($param['dest']) && !empty($param['dest'])){
            $where[] = ['chai.dest','like', '%'.$param['dest'].'%'];
        }
        if(isset($param['startdt']) && !empty($param['startdt'])){
            $where[] = ['chai.startdt','between', explode(' - ', $param['startdt'])];
        }
        if(isset($param['enddt']) && !empty($param['enddt'])){
            $where[] = ['chai.enddt','between', explode(' - ', $param['enddt'])];
        }
        if(isset($param['duration']) && !empty($param['duration'])){
            $where[] = ['chai.duration','like', '%'.$param['duration'].'%'];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['chai.status','=', $param['status']];
        }


        $data['data'] = KaochaiModel::alias('chai')
            ->field('chai.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('kao_chai', 'chai'))
            ->order('chai.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('kao_chai');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_kao_chai(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['userid'])){
                return outputJson(4000, '请选择加班人员');
            }
            if(empty($param['chudi'])){
                return outputJson(4000, '请输入出发地');
            }
            if(empty($param['dest'])){
                return outputJson(4000, '请输入目的地');
            }
            if(empty($param['startdt'])){
                return outputJson(4000, '请选择开始时间');
            }
            if(empty($param['enddt'])){
                return outputJson(4000, '请选择结束时间');
            }
            if(empty($param['duration'])){
                return outputJson(4000, '请输入时长');
            }

            $param['comid'] = $this->userinfo['comid'];
            $param['status'] = 1;
            $param['isturn'] = 1;
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];
            $param['chanid'] = (new UserService())->get_user_chanid();


            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);


            Db::startTrans();
            try {
                $id = KaochaiModel::insertGetId($param);
                (new OptService())->relation_file($files,'kao_chai',$id);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'kao_chai', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'kao_chai', $id, '出差');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            return outputJson(2000,lang('code_2000'), []);
        }
    }
    public function edit_kao_chai(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['userid'])){
                return outputJson(4000, '请选择加班人员');
            }
            if(empty($param['chudi'])){
                return outputJson(4000, '请输入出发地');
            }
            if(empty($param['dest'])){
                return outputJson(4000, '请输入目的地');
            }
            if(empty($param['startdt'])){
                return outputJson(4000, '请选择开始时间');
            }
            if(empty($param['enddt'])){
                return outputJson(4000, '请选择结束时间');
            }
            if(empty($param['duration'])){
                return outputJson(4000, '请输入时长');
            }


            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');

            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);



            Db::startTrans();
            try {
                KaochaiModel::update($param);
                (new OptService())->relation_file($files,'kao_chai',$param['id']);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'kao_chai', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'kao_chai', $param['id'], '出差');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = KaochaiModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }

            $data['data']['userid_info'] = (new UserService())->get_users_part_arr($data['data']['userid'], 'user');

            $data['files'] = (new OptService())->get_file('kao_chai', $data['data']['id']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_kao_chai(Request $request){
        $param = $request->post();
        $data = KaochaiModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            KaochaiModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'kao_chai', $data['id'], '出差');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_kao_chai(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = KaochaiModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }


        $data['files'] = (new OptService())->get_file('kao_chai', $data['data']['id']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }




    public function list_huidept(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['hui.deleted_user','=', 0];
        $where[] = ['hui.comid','=',$this->userinfo['comid']];


        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['hui.title|hui.depter|hui.huier','like', '%'.$param['keyword'].'%'];
        }

        $data['data'] = HuiModel::alias('hui')
            ->field('hui.depter,count(hui.depter) as nums')
            ->where($where)
            ->where((new MenuService())->get_miss_where('hui', 'hui'))
            ->order('hui.id DESC')
            ->group('hui.depter')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['depter_name'] = DeptModel::get_name_by_pk($item['depter']);
                return $item;
            })->toArray();
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function list_hui(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['hui.deleted_user','=', 0];
        $where[] = ['hui.comid','=',$this->userinfo['comid']];
        $where[] = ['hui.created_user','=',$this->userinfo['id']];

        if(isset($param['huitype']) && !empty($param['huitype'])){
            $where[] = ['hui.huitype','=', $param['huitype']];
        }
        if(isset($param['title']) && !empty($param['title'])){
            $where[] = ['hui.title','like', '%'.$param['title'].'%'];
        }
        if(isset($param['created_at']) && !empty($param['created_at'])){
            $where[] = ['hui.created_at','between', explode(' - ', $param['created_at'])];
        }

        $data['huitype'] = (new OptService())->get_base_info('qi_hui_huitype');
        $data['is_huitype'] = isset($param['huitype']) ? $param['huitype'] : '';

        $data['data'] = HuiModel::alias('hui')
            ->field('hui.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('hui', 'hui'))
            ->order('hui.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['huier'] = UserModel::get_realname_by_pk($item['huier']);
                $item['huitype'] = (new OptService())->get_base_showname('qi_hui_huitype', $item['huitype']);
                $item['porter_name'] = UserModel::get_realname_by_ids($item['porter']);
                $item['reader_name'] = UserModel::get_realname_by_ids($item['reader']);
                $item['depter_name'] = DeptModel::get_name_by_pk($item['depter']);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('hui');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function list_huimy(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['hui.deleted_user','=', 0];
        $where[] = ['hui.comid','=',$this->userinfo['comid']];

        $whereporter = Db::raw("FIND_IN_SET(".$this->userinfo['id'].",`hui`.`porter`)");


        if(isset($param['huitype']) && !empty($param['huitype'])){
            $where[] = ['hui.huitype','=', $param['huitype']];
        }
        if(isset($param['title']) && !empty($param['title'])){
            $where[] = ['hui.title','like', '%'.$param['title'].'%'];
        }
        if(isset($param['huier_name']) && !empty($param['huier_name'])){
            $where[] = ['user.realname','like', '%'.$param['huier_name'].'%'];
        }
        if(isset($param['depter_name']) && !empty($param['depter_name'])){
            $where[] = ['dept.name','like', '%'.$param['depter_name'].'%'];
        }

        $data['huitype'] = (new OptService())->get_base_info('qi_hui_huitype');
        $data['is_huitype'] = isset($param['huitype']) ? $param['huitype'] : '';

        $data['data'] = HuiModel::alias('hui')
            ->field('hui.*,user.realname as huier_name,dept.name as depter_name')
            ->join('user user','user.id=hui.huier')
            ->join('dept dept','dept.id=hui.depter')
            ->where($where)
            ->where($whereporter)
            ->order('hui.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['huitype'] = (new OptService())->get_base_showname('qi_hui_huitype', $item['huitype']);
                $item['porter_name'] = UserModel::get_realname_by_ids($item['porter']);

                $item['read'] = '未阅';
                if(in_array($this->userinfo['id'], explode(',', $item['reader']))){
                    $item['read'] = '已阅';
                }

                return $item;
            })->toArray();

        return outputJson(2000,lang('code_2000'),$data);
    }
    public function list_huiall(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['hui.deleted_user','=', 0];
        $where[] = ['hui.comid','=',$this->userinfo['comid']];

        if(isset($param['depter']) && !empty($param['depter'])){
            $where[] = ['hui.depter','=', $param['depter']];
        }
        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['hui.title|user.realname','like', '%'.$param['keyword'].'%'];
        }



        if(isset($param['huitype']) && !empty($param['huitype'])){
            $where[] = ['hui.huitype','=', $param['huitype']];
        }
        if(isset($param['title']) && !empty($param['title'])){
            $where[] = ['hui.title','like', '%'.$param['title'].'%'];
        }
        if(isset($param['created_at']) && !empty($param['created_at'])){
            $where[] = ['hui.created_at','between', explode(' - ', $param['created_at'])];
        }
        if(isset($param['huier_name']) && !empty($param['huier_name'])){
            $where[] = ['user.realname','like', '%'.$param['huier_name'].'%'];
        }
        if(isset($param['depter_name']) && !empty($param['depter_name'])){
            $where[] = ['dept.name','like', '%'.$param['depter_name'].'%'];
        }


        $data['huitype'] = (new OptService())->get_base_info('qi_hui_huitype');
        $data['is_huitype'] = isset($param['huitype']) ? $param['huitype'] : '';

        $data['data'] = HuiModel::alias('hui')
            ->field('hui.*,user.realname as huier_name,dept.name as depter_name')
            ->join('user user','user.id=hui.huier')
            ->join('dept dept','dept.id=hui.depter')
            ->where((new MenuService())->get_miss_where('huiall', 'hui'))
            ->where($where)
            ->order('hui.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['huitype'] = (new OptService())->get_base_showname('qi_hui_huitype', $item['huitype']);
                $item['porter_name'] = UserModel::get_realname_by_ids($item['porter']);
                return $item;
            })->toArray();

        return outputJson(2000,lang('code_2000'),$data);
    }
    public function add_hui(Request $request){
        if($request->isPost()){
            $param = $request->post();

            if(empty($param['huitype'])){
                return outputJson(4000, '请选择汇报类型');
            }
            if(empty($param['huitype'])){
                return outputJson(4000, '请输入汇报主题');
            }
            if(empty($param['porter'])){
                return outputJson(4000, '请选择汇报对象');
            }


            $param['comid'] = $this->userinfo['comid'];
            $param['created_user'] = $param['updated_user'] = $this->userinfo['id'];
            $param['created_at'] = $param['updated_at']= date('Y-m-d H:i:s');
            $param['deptid'] = $this->userinfo['deptid'];
            $param['chanid'] = (new UserService())->get_user_chanid();
            $param['huier'] = $this->userinfo['id'];
            $param['depter'] = $this->userinfo['deptid'];


            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);


            Db::startTrans();
            try {
                $id = HuiModel::insertGetId($param);
                (new OptService())->relation_file($files,'hui',$id);
                (new OptService())->add_flow_log(FlowLogModel::SET_ADD, 'hui', $id);
                (new OptService())->add_log_list(FlowLogModel::SET_ADD, 'hui', $id, '工作汇报');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $data['huier'] = $this->userinfo['realname'];
            $data['depter'] = DeptModel::get_name_by_pk($this->userinfo['deptid']);
            $data['huitype'] = (new OptService())->get_base_info('qi_hui_huitype');
            return outputJson(2000,lang('code_2000'), $data);
        }
    }
    public function edit_hui(Request $request){
        if($request->isPost()){
            $param = $request->post();
            $old = HuiModel::where(['id'=>$param['id']])->find();

            if(empty($param['huitype'])){
                return outputJson(4000, '请选择汇报类型');
            }
            if(empty($param['huitype'])){
                return outputJson(4000, '请输入汇报主题');
            }
            if(empty($param['porter'])){
                return outputJson(4000, '请选择汇报对象');
            }
            $param['updated_user'] = $this->userinfo['id'];
            $param['updated_at'] = date('Y-m-d H:i:s');
            $files = array_filter($param['files']);
            unset($param['files']);
            unset($param['token']);



            Db::startTrans();
            try {
                HuiModel::update($param);
                (new OptService())->relation_file($files,'hui',$param['id']);
                (new OptService())->add_flow_log(FlowLogModel::SET_EDIT, 'hui', $param['id']);
                (new OptService())->add_log_list(FlowLogModel::SET_EDIT, 'hui', $param['id'], '工作汇报');
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                return outputJson(4000,lang('code_4000'));
            }
            return outputJson(2000,lang('code_2000'));
        }else{
            $id = $request->get('id',0,'int');
            $data['data'] = HuiModel::where(['id'=>$id])->find();
            if(!$data['data']){
                return outputJson(4000, lang('code_4000'));
            }
            $data['data']['porter_info'] = (new UserService())->get_users_part_arr($data['data']['porter'], 'user');
            $data['data']['huier'] = UserModel::get_realname_by_pk($data['data']['huier']);
            $data['data']['depter'] = DeptModel::get_name_by_pk($data['data']['depter']);
            $data['huitype'] = (new OptService())->get_base_info('qi_hui_huitype');
            $data['files'] = (new OptService())->get_file('hui', $data['data']['id']);
            return outputJson(2000,lang('code_2000'),$data);
        }
    }
    public function del_hui(Request $request){
        $param = $request->post();
        $data = HuiModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            HuiModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'hui', $data['id'], '工作汇报');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_hui(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = HuiModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }

        $readerArr = explode(',', $data['data']['reader'].','.$this->userinfo['id']);
        $reader = implode(',', array_unique($readerArr));
        HuiModel::where(['id'=>$data['data']['id']])->update(['reader'=>$reader]);
        $data['data'] = HuiModel::get_info_by_pk($id);

        $data['data']['huitype'] = (new OptService())->get_base_showname('qi_hui_huitype', $data['data']['huitype']);
        $data['data']['huier'] = UserModel::get_realname_by_pk($data['data']['huier']);
        $data['data']['depter'] = DeptModel::get_name_by_pk($data['data']['depter']);

        $data['data']['porter_name'] = UserModel::get_realname_by_ids($data['data']['porter']);

        $data['files'] = (new OptService())->get_file('hui', $data['data']['id']);
        return outputJson(2000,lang('code_2000'), $data);
    }




    public function list_cert_perru(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['arc.deleted_user','=', 0];
        $where[] = ['arc.comid','=',$this->userinfo['comid']];
        $where[] = ['arc.isturn','=',1];
        $where[] = ['arc.status','in',[0,1]];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['arc.name|arc.number|arc.idcard|arc.nation|arc.jiguan|arc.mian|arc.tel','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['name']) && !empty($param['name'])){
            $where[] = ['arc.name','like', '%'.$param['name'].'%'];
        }
        if(isset($param['number']) && !empty($param['number'])){
            $where[] = ['arc.number','like', '%'.$param['number'].'%'];
        }
        if(isset($param['idcard']) && !empty($param['idcard'])){
            $where[] = ['arc.idcard','like', '%'.$param['idcard'].'%'];
        }
        if(isset($param['sex']) && !empty($param['sex'])){
            $where[] = ['arc.sex','=', $param['sex']];
        }
        if(isset($param['birdt']) && !empty($param['birdt'])){
            $where[] = ['arc.birdt','between', explode(' - ', $param['birdt'])];
        }
        if(isset($param['nation']) && !empty($param['nation'])){
            $where[] = ['arc.nation','like', '%'.$param['nation'].'%'];
        }
        if(isset($param['jiguan']) && !empty($param['jiguan'])){
            $where[] = ['arc.jiguan','like', '%'.$param['jiguan'].'%'];
        }
        if(isset($param['mian']) && !empty($param['mian'])){
            $where[] = ['arc.mian','like', '%'.$param['mian'].'%'];
        }
        if(isset($param['addr']) && !empty($param['addr'])){
            $where[] = ['arc.addr','like', '%'.$param['addr'].'%'];
        }
        if(isset($param['tel']) && !empty($param['tel'])){
            $where[] = ['arc.tel','like', '%'.$param['tel'].'%'];
        }
        if(isset($param['jiner']) && !empty($param['jiner'])){
            $where[] = ['arc.jiner','like', '%'.$param['jiner'].'%'];
        }
        if(isset($param['jintel']) && !empty($param['jintel'])){
            $where[] = ['arc.jintel','like', '%'.$param['jintel'].'%'];
        }
        if(isset($param['school']) && !empty($param['school'])){
            $where[] = ['arc.school','like', '%'.$param['school'].'%'];
        }
        if(isset($param['xueli']) && !empty($param['xueli'])){
            $where[] = ['arc.xueli','=', $param['xueli']];
        }
        if(isset($param['major']) && !empty($param['major'])){
            $where[] = ['arc.major','like', '%'.$param['major'].'%'];
        }
        if(isset($param['schooldt']) && !empty($param['schooldt'])){
            $where[] = ['arc.schooldt','between', explode(' - ', $param['schooldt'])];
        }
        if(isset($param['zhilevel']) && !empty($param['zhilevel'])){
            $where[] = ['arc.zhilevel','like', '%'.$param['zhilevel'].'%'];
        }

        if(isset($param['nature']) && !empty($param['nature'])){
            $where[] = ['arc.nature','=', $param['nature']];
        }
        if(isset($param['intodt']) && !empty($param['intodt'])){
            $where[] = ['arc.intodt','between', explode(' - ', $param['intodt'])];
        }

        if(isset($param['outdt']) && !empty($param['outdt'])){
            $where[] = ['arc.outdt','between', explode(' - ', $param['outdt'])];
        }
        if(isset($param['outtype']) && !empty($param['outtype'])){
            $where[] = ['arc.outtype','=', $param['outtype']];
        }
        if(isset($param['deptid']) && !empty($param['deptid'])){
            $where[] = ['arc.deptid','=', $param['deptid']];
        }
        $whereGangid = '';
        if(isset($param['gangid']) && $param['gangid'] != ''){
            $whereGangid = Db::raw("FIND_IN_SET(".$param['gangid'].",`arc`.`gangid`)");
        }

        if(isset($param['shenum']) && !empty($param['shenum'])){
            $where[] = ['arc.shenum','like', '%'.$param['shenum'].'%'];
        }
        if(isset($param['gongnum']) && !empty($param['gongnum'])){
            $where[] = ['arc.gongnum','like', '%'.$param['gongnum'].'%'];
        }
        if(isset($param['bankname']) && !empty($param['bankname'])){
            $where[] = ['arc.bankname','like', '%'.$param['bankname'].'%'];
        }
        if(isset($param['banknum']) && !empty($param['banknum'])){
            $where[] = ['arc.banknum','like', '%'.$param['banknum'].'%'];
        }
        if(isset($param['bankkai']) && !empty($param['bankkai'])){
            $where[] = ['arc.bankkai','like', '%'.$param['bankkai'].'%'];
        }

        $data['nature'] = (new OptService())->get_base_info('person_nature');
        $data['is_nature'] = isset($param['nature']) ? $param['nature'] : '';

        $data['xueli'] = (new OptService())->get_base_info('person_xueli');
        $data['is_xueli'] = isset($param['xueli']) ? $param['xueli'] : '';

        $data['gangArr'] = (new UserService())->get_usergang_all();
        $data['is_gangid'] = isset($param['gangid']) ? $param['gangid'] : '';

        $data['data'] = CertPerruModel::alias('arc')
            ->field('arc.*')
            ->where($where)
            ->where($whereGangid)
            ->where((new MenuService())->get_miss_where('cert_perru', 'arc'))
            ->order('arc.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['deptid_name'] = DeptModel::get_name_by_pk($item['deptid']);
                $item['gangid_name'] = UserGangModel::get_name_by_ids($item['gangid'],' / ');
                $item['nature'] = (new OptService())->get_base_showname('person_nature', $item['nature']);
                $item['xueli'] = (new OptService())->get_base_showname('person_xueli', $item['xueli']);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('cert_perru');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function del_cert_perru(Request $request){
        $param = $request->post();
        $data = CertPerruModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            CertPerruModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'cert_perru', $data['id'], '入职审批');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_cert_perru(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = CertPerruModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }

        $data['data']['deptid_name'] = DeptModel::get_name_by_pk($data['data']['deptid']);
        $data['data']['gangid_name'] = UserGangModel::get_name_by_ids($data['data']['gangid'],' / ');
        $data['data']['nature'] = (new OptService())->get_base_showname('person_nature',$data['data']['nature']);
        $data['data']['xueli'] = (new OptService())->get_base_showname('person_xueli',$data['data']['xueli']);

        $data['data']['chanid_name'] = DeptModel::get_name_by_pk($data['data']['chanid']);
        $data['data']['age'] = (new CertService())->get_age_by_idcard($data['data']['idcard']);

        $data['files'] = (new OptService())->get_file('cert_perru', $data['data']['id']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }


    public function list_cert_zhao(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['zhao.deleted_user','=', 0];
        $where[] = ['zhao.comid','=',$this->userinfo['comid']];
        $where[] = ['zhao.isturn','=',1];
        $where[] = ['zhao.status','in',[0,1]];

        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['zhao.flowuser|zhao.flowdept|xu.name|zhao.gangxu|zhao.zhaonum|zhao.xincon|zhao.zhaocon|zhao.gangcon|zhao.rencon|zhao.jindu','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['flowuser']) && !empty($param['flowuser'])){
            $where[] = ['zhao.flowuser','like', '%'.$param['flowuser'].'%'];
        }
        if(isset($param['flowdept']) && !empty($param['flowdept'])){
            $where[] = ['zhao.flowdept','like', '%'.$param['flowdept'].'%'];
        }
        if(isset($param['deptxu_name']) && !empty($param['deptxu_name'])){
            $where[] = ['xu.name','like', '%'.$param['deptxu_name'].'%'];
        }
        if(isset($param['gangxu']) && !empty($param['gangxu'])){
            $where[] = ['zhao.gangxu','like', '%'.$param['gangxu'].'%'];
        }
        if(isset($param['zhaonum']) && !empty($param['zhaonum'])){
            $where[] = ['zhao.zhaonum','like', '%'.$param['zhaonum'].'%'];
        }
        if(isset($param['xincon']) && !empty($param['xincon'])){
            $where[] = ['zhao.xincon','like', '%'.$param['xincon'].'%'];
        }
        if(isset($param['zhaocon']) && !empty($param['zhaocon'])){
            $where[] = ['zhao.zhaocon','like', '%'.$param['zhaocon'].'%'];
        }
        if(isset($param['gangcon']) && !empty($param['gangcon'])){
            $where[] = ['zhao.gangcon','like', '%'.$param['gangcon'].'%'];
        }
        if(isset($param['rencon']) && !empty($param['rencon'])){
            $where[] = ['zhao.rencon','like', '%'.$param['rencon'].'%'];
        }
        if(isset($param['qidt']) && !empty($param['qidt'])){
            $where[] = ['zhao.qidt','between', explode(' - ', $param['qidt'])];
        }
        if(isset($param['jindu']) && !empty($param['jindu'])){
            $where[] = ['zhao.jindu','=', $param['jindu']];
        }


        $data['jindu'] = (new CertService())->get_cert_zhao_jindu();
        $data['is_jindu'] = isset($param['jindu']) ? $param['jindu'] : '';

        $data['data'] = CertZhaoModel::alias('zhao')
            ->field('zhao.*,xu.name as deptxu_name')
            ->join('dept xu','xu.id=zhao.deptxu')
            ->where($where)
            ->where((new MenuService())->get_miss_where('cert_zhao', 'zhao'))
            ->order('zhao.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('cert_zhao');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function del_cert_zhao(Request $request){
        $param = $request->post();
        $data = CertZhaoModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            CertZhaoModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'cert_zhao', $data['id'], '招聘需求');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_cert_zhao(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = CertZhaoModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }

        $data['data']['deptxu_name'] = DeptModel::get_name_by_pk($data['data']['deptxu']);


        $data['files'] = (new OptService())->get_file('cert_zhao', $data['data']['id']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }



    public function list_archive_jiao(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['jiao.deleted_user','=', 0];
        $where[] = ['jiao.comid','=',$this->userinfo['comid']];
        $where[] = ['jiao.isturn','=',1];
        $where[] = ['jiao.status','in',[0,1]];


        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['jiao.flowuser|jiao.flowdept|jiao.dept|jiao.gang|jiaoer.realname','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['flowuser']) && !empty($param['flowuser'])){
            $where[] = ['jiao.flowuser','like', '%'.$param['flowuser'].'%'];
        }
        if(isset($param['flowdept']) && !empty($param['flowdept'])){
            $where[] = ['jiao.flowdept','like', '%'.$param['flowdept'].'%'];
        }
        if(isset($param['dept']) && !empty($param['dept'])){
            $where[] = ['jiao.dept','like', '%'.$param['dept'].'%'];
        }
        if(isset($param['gang']) && !empty($param['gang'])){
            $where[] = ['jiao.gang','like', '%'.$param['gang'].'%'];
        }
        if(isset($param['intodt']) && !empty($param['intodt'])){
            $where[] = ['jiao.intodt','between', explode(' - ', $param['intodt'])];
        }
        if(isset($param['outshendt']) && !empty($param['outshendt'])){
            $where[] = ['jiao.outshendt','between', explode(' - ', $param['outshendt'])];
        }
        if(isset($param['outshidt']) && !empty($param['outshidt'])){
            $where[] = ['jiao.outshidt','between', explode(' - ', $param['outshidt'])];
        }
        if(isset($param['jiaoer_name']) && !empty($param['jiaoer_name'])){
            $where[] = ['jiaoer.realname','like', '%'.$param['jiaoer_name'].'%'];
        }
        if(isset($param['jiaodt']) && !empty($param['jiaodt'])){
            $where[] = ['jiao.jiaodt','between', explode(' - ', $param['jiaodt'])];
        }


        $data['data'] = ArchiveJiaoModel::alias('jiao')
            ->field('jiao.*,jiaoer.realname as jiaoer_name')
            ->join('user jiaoer','jiaoer.id=jiao.jiaoer')
            ->where($where)
            ->where((new MenuService())->get_miss_where('archive_jiao', 'jiao'))
            ->order('jiao.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('archive_jiao');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function del_archive_jiao(Request $request){
        $param = $request->post();
        $data = ArchiveJiaoModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            ArchiveJiaoModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'archive_jiao', $data['id'], '离职交接');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_archive_jiao(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = ArchiveJiaoModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }

        $data['data']['jiaoer_name'] = UserModel::get_realname_by_pk(['id'=>$data['data']['jiaoer']]);

        $list = ArchiveJiaoListModel::where(['jiaoid'=>$data['data']['id']])->select()->toArray();
        $data['list'] = $list;

        $data['files'] = (new OptService())->get_file('archive_jiao', $data['data']['id']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }









    public function human_count_renliu(Request $request){
        $param = $request->post();

        $month = '';
        if(isset($param['month']) && !empty($param['month'])){
            $month = $param['month'];
        }

        $data['data'] = $this->human_count_renliu_deptinfo(0, $month);
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function human_count_renliu_deptinfo($pid=0, $month){
        $data = DeptModel::field('*,id as value')->where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'pid'=>$pid])->order('sort ASC')->select()->toArray();
        foreach ($data as &$item){
            $item['allnum'] = CertPersonModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'deptid'=>$item['id']])->count();
            $item['yue_ru'] = 0;
            $item['yue_out'] = 0;
            $item['year_ru'] = 0;
            $item['year_out'] = 0;
            if($month){
                $mon1 = $month.'-01';
                $mon2 = date("Y-m-d", strtotime("+1 month -1 day", strtotime($mon1)));
                $item['yue_ru'] = CertPersonModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'deptid'=>$item['id']])
                    ->where('intodt','between',[$mon1, $mon2])->count();
                $item['yue_out'] = CertPersonModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'deptid'=>$item['id']])
                    ->where('outdt','between',[$mon1, $mon2])->count();

                $year1 = date("Y-01-01", strtotime($mon1));
                $year2 = date("Y-m-d", strtotime("+1 year -1 day", strtotime($year1)));
                $item['year_ru'] = CertPersonModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'deptid'=>$item['id']])
                    ->where('intodt','between',[$year1, $year2])->count();
                $item['year_out'] = CertPersonModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'deptid'=>$item['id']])
                    ->where('outdt','between',[$year1, $year2])->count();
            }










            $item['children'] = $this->human_count_renliu_deptinfo($item['id'], $month);
        }
        return $data;
    }
    public function human_count_yuansheng(Request $request){
        $param = $request->post();
        get_page($param);
        $where[] = ['deleted_user','=','0'];
        $where[] = ['comid','=',$this->userinfo['comid']];

        if(isset($param['chanid']) && !empty($param['chanid'])){
            $where[] = ['chanid','=', $param['chanid']];
        }

        $data['chanid'] = (new UserService())->get_chaninfo_all();
        $data['is_chanid'] = isset($param['chanid']) ? $param['chanid'] : '';



        $whereMonth = '';
        if(isset($param['month']) && !empty($param['month'])){
            $monthnum = date("m", strtotime($param['month'].'-01'));
            $monthnum = (int)$monthnum;
            $whereMonth = Db::raw("MONTH(birdt)=".$monthnum);
        }else{
            $where[] = ['id','<', 0];
        }
        $data['data'] = CertPersonModel::field('id,name,deptid,birdt')
            ->where($where)
            ->where($whereMonth)
            ->order('id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['deptid_name'] = DeptModel::get_name_by_pk($item['deptid']);
                return $item;
            })->toArray();

        return outputJson(2000,lang('code_2000'),$data);
    }








    public function list_tongyong(Request $request){
        $param = $request->post();
        get_page($param);

        $where[] = ['ty.deleted_user','=', 0];
        $where[] = ['ty.comid','=',$this->userinfo['comid']];
        $where[] = ['ty.isturn','=',1];
        $where[] = ['ty.status','in',[0,1]];


        if(isset($param['keyword']) && !empty($param['keyword'])){
            $where[] = ['ty.zhai|ty.nei','like', '%'.$param['keyword'].'%'];
        }
        if(isset($param['zhai']) && !empty($param['zhai'])){
            $where[] = ['ty.zhai','like', '%'.$param['zhai'].'%'];
        }
        if(isset($param['nei']) && !empty($param['nei'])){
            $where[] = ['ty.nei','like', '%'.$param['nei'].'%'];
        }
        if(isset($param['shilei']) && !empty($param['shilei'])){
            $where[] = ['ty.shilei','=', $param['shilei']];
        }
        if(isset($param['status']) && $param['status'] != ''){
            $where[] = ['ty.status','=', $param['status']];
        }

        $data['shilei'] = (new OptService())->get_base_info('qi_tongyong_shilei');
        $data['is_shilei'] = isset($param['shilei']) ? $param['shilei'] : '';



        $data['data'] = TongyongModel::alias('ty')
            ->field('ty.*')
            ->where($where)
            ->where((new MenuService())->get_miss_where('tongyong', 'ty'))
            ->order('ty.id DESC')
            ->paginate($param['pagesize'],false,['page'=>$param['page']])
            ->each(function ($item,$key){
                $item['shilei'] = (new OptService())->get_base_showname('qi_tongyong_shilei', $item['shilei']);
                $item['created_user_name'] = UserModel::get_realname_by_pk($item['created_user']);
                return $item;
            })->toArray();

        $data['butauth'] = (new MenuService())->get_butauth('tongyong');
        return outputJson(2000,lang('code_2000'),$data);
    }
    public function del_tongyong(Request $request){
        $param = $request->post();
        $data = TongyongModel::get_info_by_pk($param['id']);
        if(!$data){
            return outputJson(4000,lang('code_4000'));
        }

        Db::startTrans();
        try {
            FlowBillModel::where(['id'=>$data['billid']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            TongyongModel::where(['id'=>$data['id']])->update([
                'deleted_user' => $this->userinfo['id'],
                'deleted_at' => date('Y-m-d H:i:s')
            ]);
            (new OptService())->add_log_list(FlowLogModel::SET_DELETE, 'tongyong', $data['id'], '通用审批流程');
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            return outputJson(4000,lang('code_4000'));
        }
        return outputJson(2000,lang('code_2000'));
    }
    public function show_tongyong(Request $request){
        $id = $request->post('id', 0, 'int');
        $data['data'] = TongyongModel::get_info_by_pk($id);
        if(!$data['data']){
            return outputJson(4000, lang('code_4000'));
        }

        $data['data']['shilei'] = (new OptService())->get_base_showname('qi_tongyong_shilei', $data['data']['shilei']);
        $data['files'] = (new OptService())->get_file('tongyong', $data['data']['id']);
        $data['billinfo'] = (new FlowService())->get_flow_show_info($data['data']['billid']);
        return outputJson(2000,lang('code_2000'), $data);
    }



}
